﻿using System;
namespace Producers.Kis.Xtee.Riik.Ee.Producer.Kis {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="DebtSettlement", Namespace="http://producers.kis.xtee.riik.ee/producer/kis", Target=typeof(DebtSettlement))]
    public class DebtSettlementSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IDebtSettlement clazz;
        
        public DebtSettlementSerializer(IDebtSettlement clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("PaymentRecipient");
            if (clazz.PaymentRecipient!=null) {
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "NonEmptyString");
                Writer.WriteString(clazz.PaymentRecipient.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : PaymentRecipient");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("Bank");
            if (clazz.Bank!=null) {
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "NonEmptyString");
                Writer.WriteString(clazz.Bank.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Bank");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("Account");
            if (clazz.Account!=null) {
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "NonEmptyString");
                Writer.WriteString(clazz.Account.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Account");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("Statement");
            if (clazz.Statement!=null) {
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "NonEmptyString");
                Writer.WriteString(clazz.Statement.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Statement");
            }
            Writer.WriteEndElement();
            if (clazz.ReferenceNumber!=null) {
                Writer.WriteStartElement("ReferenceNumber");
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "NonEmptyString");
                Writer.WriteString(clazz.ReferenceNumber.ToString());
                Writer.WriteEndElement();
            }
            if (clazz.IBAN!=null) {
                Writer.WriteStartElement("IBAN");
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "NonEmptyString");
                Writer.WriteString(clazz.IBAN.ToString());
                Writer.WriteEndElement();
            }
            if (clazz.SWIFT!=null) {
                Writer.WriteStartElement("SWIFT");
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "NonEmptyString");
                Writer.WriteString(clazz.SWIFT.ToString());
                Writer.WriteEndElement();
            }
            if (clazz.BankCode!=null) {
                Writer.WriteStartElement("BankCode");
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "NonEmptyString");
                Writer.WriteString(clazz.BankCode.ToString());
                Writer.WriteEndElement();
            }
            Writer.WriteStartElement("IsDomestic");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "boolean");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdBoolean(((bool)(clazz.IsDomestic))).ToString());
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="PaymentRecipient") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>DebtSettlement>PaymentRecipient");
                }
                clazz.PaymentRecipient = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.NonEmptyString(Reader.ReadElementString("PaymentRecipient"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>DebtSettlement>PaymentRecipient", Reader.LocalName);
            }
            if (Reader.LocalName=="Bank") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>DebtSettlement>Bank");
                }
                clazz.Bank = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.NonEmptyString(Reader.ReadElementString("Bank"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>DebtSettlement>Bank", Reader.LocalName);
            }
            if (Reader.LocalName=="Account") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>DebtSettlement>Account");
                }
                clazz.Account = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.NonEmptyString(Reader.ReadElementString("Account"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>DebtSettlement>Account", Reader.LocalName);
            }
            if (Reader.LocalName=="Statement") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>DebtSettlement>Statement");
                }
                clazz.Statement = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.NonEmptyString(Reader.ReadElementString("Statement"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>DebtSettlement>Statement", Reader.LocalName);
            }
            if (Reader.LocalName=="ReferenceNumber") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>DebtSettlement>ReferenceNumber");
                }
                clazz.ReferenceNumber = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.NonEmptyString(Reader.ReadElementString("ReferenceNumber"));
            }
            if (Reader.LocalName=="IBAN") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>DebtSettlement>IBAN");
                }
                clazz.IBAN = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.NonEmptyString(Reader.ReadElementString("IBAN"));
            }
            if (Reader.LocalName=="SWIFT") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>DebtSettlement>SWIFT");
                }
                clazz.SWIFT = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.NonEmptyString(Reader.ReadElementString("SWIFT"));
            }
            if (Reader.LocalName=="BankCode") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>DebtSettlement>BankCode");
                }
                clazz.BankCode = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.NonEmptyString(Reader.ReadElementString("BankCode"));
            }
            if (Reader.LocalName=="IsDomestic") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>DebtSettlement>IsDomestic");
                }
                clazz.IsDomestic = new global::Xtee.Core.Schema.XsdBoolean(Reader.ReadElementString("IsDomestic")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>DebtSettlement>IsDomestic", Reader.LocalName);
            }
        }
    }
}
